package com.shuai.orderfood.merchants.controller;

import com.shuai.orderfood.common.Result;
import com.shuai.orderfood.merchants.dto.LoginDto;
import com.shuai.orderfood.merchants.vo.LoginVo;
import com.shuai.orderfood.merchants.dto.RegisterDto;
import com.shuai.orderfood.merchants.service.impl.AuthServiceImpl;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * 认证控制器
 */
@RestController
@RequestMapping("/merchants")
@CrossOrigin
public class AuthController {

    @Resource
    private AuthServiceImpl authService;

    /**
     * 用户注册
     */
    @PostMapping("/register")
    public Result<Void> register(@Valid @RequestBody RegisterDto request) throws Exception {
        authService.register(request);
        return Result.success();
    }

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result<LoginVo> login(@Valid @RequestBody LoginDto request) throws Exception {
        LoginVo response = authService.login(request);
        return Result.success(response);
    }
} 